package aorey.web;

import java.io.IOException;
import java.util.HashMap;

import org.beetl.core.Configuration;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;
import org.beetl.core.resource.FileResourceLoader;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;

public class WebTemplate {

	protected GroupTemplate groupTemplate ;
	
	
	public WebTemplate(String dir) throws IOException
	{
		FileResourceLoader resourceLoader = new FileResourceLoader(dir,"utf-8");
		Configuration cfg = Configuration.defaultConfiguration();
		this.groupTemplate = new GroupTemplate(resourceLoader,cfg);
	}
	
	
	public String getTemplate(String fileName)
	{
		Template template = this.groupTemplate.getTemplate(fileName);
		return template.render();
	}
	
	
	/**
	 * 绑定数据
	 * @param data
	 */
	public void bind(HashMap<String, Object> data)
	{
//		this.groupTemplate
		this.groupTemplate.setSharedVars(data);
	}
}
